<?php
namespace app\beautiful\middleware;
use app\beautiful\model\StaffModel;

class StaffCheck{
    use \app\BaseTrait;

    /**
     * 处理请求
     *  验证是否登录是否正确的中间件
     * @param \think\Request $request
     * @param \Closure       $next
     * @return Response
     */
    public function handle($request, \Closure $next)
    {
        if(empty($request->member->mobile)){
            return $this->error('你并没有权限',100);
        }
        $mobile=$request->member->mobile;
        if(null === $staff = StaffModel::where([
                ['mobile','=',$mobile],
                ['shop_id','=',$request->shopId],
                ['status','=',1],
                ['is_delete','=',0]
            ])->find()){
            return $this->error('你并没有权限',100);
        }
        $request->staff=$staff;
        $request->staffId=$staff->staff_id;
        return $next($request);
    }
}
